package com.xiaochen.manager.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaochen.manager.mapper.CategoryBrandMapper;
import com.xiaochen.manager.service.CategoryBrandService;
import com.xiaochen.model.dto.product.CategoryBrandDto;
import com.xiaochen.model.entity.product.Brand;
import com.xiaochen.model.entity.product.CategoryBrand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 分类-品牌服务实现类
 *
 * @author pinkhors
 */
@Service
public class CategoryBrandServiceImpl implements CategoryBrandService {

    @Autowired
    private CategoryBrandMapper categoryBrandMapper;

    /**
     * 多条件(CategoryBrand 分类ID 和 品牌ID)分页查询
     * @param categoryBrandDto
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<CategoryBrand> selectByPage(CategoryBrandDto categoryBrandDto, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<CategoryBrand> list = categoryBrandMapper.selectByPage(categoryBrandDto);
        PageInfo<CategoryBrand> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 分类-品牌的添加
     */
    @Override
    public void saveCategoryBrand(CategoryBrand categoryBrand) {
        categoryBrandMapper.saveCategoryBrand(categoryBrand);
    }

    /**
     * 分类-品牌的删除
     */
    @Override
    public void deleteCategoryBrand(Long id) {
        categoryBrandMapper.deleteCategoryBrand(id);
    }

    /**
     * 分类-品牌的修改
     */
    @Override
    public void updateCategoryBrand(CategoryBrand categoryBrand) {
        categoryBrandMapper.updateCategoryBrand(categoryBrand);
    }

    /**
     * 根据分类ID查询对应的品牌数据
     */
    @Override
    public List<Brand> selectBrandByCategoryId(Long categoryId) {
        return categoryBrandMapper.selectByCategoryId(categoryId);
    }
}
